const { request } = require('../../services/request')
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    show: {
      // 显示隐藏
      type: Boolean,
      value: true,
      observer: '_showChange'
    },

  },
  /**
   * 组件的初始数据
   */
  data: {
    userList: [],
    innerShow:false,
    wrapperShow:false
  },
  lifetimes: {
    attached() {
      //请求用户列表
this.getUserList()
this._showChange(this.data.show)
    },
  },
  /**
   * 组件的方法列表
   */
  lifetimes: {
    ready() {
      console.log('component ready')
        this._showChange(this.data.show)
    },
    attached(){
      console.log('component attached')
    }
},
  methods: {
    _showChange(show){
      if (show) {
        this.getUserList()
        this.setData({
            innerShow: true,
            wrapperShow:true
        })
    } else {
        this.setData({ innerShow: false })
        setTimeout(() => {
            this.setData({ wrapperShow: false })
        }, 300)
    }
    },
    getUserList(){
            request('POST', '/applet/answer/user/list')
      .then((res) => {
        this.setData({
          userList: res.data,
        })
      })
      .catch()
    },
    handelSelectUser(e){
      console.log('select in popup component',e)
        this.triggerEvent('selectUser', e.detail)   
    },
    createUser(){
      console.log('create user')
      wx.navigateTo({
        url: '/pages/edit-user/index?type=new',
      })
    },
    hideUserSelect(){

      this.triggerEvent('hideUserSelect')

    },
    handelRefresh(){
      this.getUserList()
    }
  },
})
